home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / misc / 39 / do2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-17  |  5.4 KB  |  248 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* do.c - version 1.0.3 */
  3.  
  4. /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
  5.  
  6. #include "hack.h"
  7.  
  8. extern struct obj *splitobj(), *addinv();
  9. extern boolean hmon();
  10. extern boolean level_exists[];
  11. extern struct monst youmonst;
  12. extern char *nomovemsg;
  13.  
  14. dodrop() {
  15.     return(drop(getobj("0$#", "drop")));
  16. }
  17.  
  18. static
  19. drop(obj) register struct obj *obj; {
  20.     if(!obj) return(0);
  21.     if(obj->olet == '$') {        /* pseudo object */
  22.         register long amount = OGOLD(obj);
  23.  
  24.         if(amount == 0)
  25.             pline("You didn't drop any gold pieces.");
  26.         else {
  27.             mkgold(amount, u.ux, u.uy);
  28.             pline("You dropped %ld gold piece%s.",
  29.                 amount, plur(amount));
  30.             if(Invisible) newsym(u.ux, u.uy);
  31.         }
  32.         free((char *) obj);
  33.         return(1);
  34.     }
  35.     if(obj->owornmask & (W_ARMOR | W_RING)){
  36.         pline("You cannot drop something you are wearing.");
  37.         return(0);
  38.     }
  39.     if(obj == uwep) {
  40.         if(uwep->cursed) {
  41.             pline("Your weapon is welded to your hand!");
  42.             return(0);
  43.         }
  44.         setuwep((struct obj *) 0);
  45.     }
  46.     pline("You dropped %s.", doname(obj));
  47.     dropx(obj);
  48.     return(1);
  49. }
  50.  
  51. /* Called in several places - should not produce texts */
  52. dropx(obj)
  53. register struct obj *obj;
  54. {
  55.     freeinv(obj);
  56.     dropy(obj);
  57. }
  58.  
  59. dropy(obj)
  60. register struct obj *obj;
  61. {
  62.     if(obj->otyp == CRYSKNIFE)
  63.         obj->otyp = WORM_TOOTH;
  64.     obj->ox = u.ux;
  65.     obj->oy = u.uy;
  66.     obj->nobj = fobj;
  67.     fobj = obj;
  68.     if(Invisible) newsym(u.ux,u.uy);
  69.     subfrombill(obj);
  70.     stackobj(obj);
  71. }
  72.  
  73. /* drop several things */
  74. doddrop() {
  75.     return(ggetobj("drop", drop, 0));
  76. }
  77.  
  78. dodown()
  79. {
  80.     if(u.ux != xdnstair || u.uy != ydnstair) {
  81.         pline("You can't go down here.");
  82.         return(0);
  83.     }
  84.     if(u.ustuck) {
  85.         pline("You are being held, and cannot go down.");
  86.         return(1);
  87.     }
  88.     if(Levitation) {
  89.         pline("You're floating high above the stairs.");
  90.         return(0);
  91.     }
  92.  
  93.     goto_level(dlevel+1, TRUE);
  94.     return(1);
  95. }
  96.  
  97. doup()
  98. {
  99.     if(u.ux != xupstair || u.uy != yupstair) {
  100.         pline("You can't go up here.");
  101.         return(0);
  102.     }
  103.     if(u.ustuck) {
  104.         pline("You are being held, and cannot go up.");
  105.         return(1);
  106.     }
  107.     if(!Levitation && inv_weight() + 5 > 0) {
  108.         pline("Your load is too heavy to climb the stairs.");
  109.         return(1);
  110.     }
  111.  
  112.     goto_level(dlevel-1, TRUE);
  113.     return(1);
  114. }
  115.  
  116. goto_level(newlevel, at_stairs)
  117. register int newlevel;
  118. register boolean at_stairs;
  119. {
  120.     register fd;
  121.     register boolean up = (newlevel < dlevel);
  122.  
  123.     if(newlevel <= 0) done("escaped");    /* in fact < 0 is impossible */
  124.     if(newlevel > MAXLEVEL) newlevel = MAXLEVEL;    /* strange ... */
  125.     if(newlevel == dlevel) return;          /* this can happen */
  126.  
  127.     glo(dlevel);
  128.     fd = creat(lock, FMASK);
  129.     if(fd < 0) {
  130.         /*
  131.          * This is not quite impossible: e.g., we may have
  132.          * exceeded our quota. If that is the case then we
  133.          * cannot leave this level, and cannot save either.
  134.          * Another possibility is that the directory was not
  135.          * writable.
  136.          */
  137.         pline("A mysterious force prevents you from going %s.",
  138.             up ? "up" : "down");
  139.         return;
  140.     }
  141.  
  142.     if(Punished) unplacebc();
  143.     u.utrap = 0;                /* needed in level_tele */
  144.     u.ustuck = 0;                /* idem */
  145.     keepdogs();
  146.     seeoff(1);
  147.     if(u.uswallow)                /* idem */
  148.         u.uswldtim = u.uswallow = 0;
  149.     flags.nscrinh = 1;
  150.     u.ux = FAR;                /* hack */
  151.     (void) inshop();            /* probably was a trapdoor */
  152.  
  153.     savelev(fd,dlevel);
  154.     (void) close(fd);
  155.     dlevel = newlevel;
  156.     if(maxdlevel < dlevel)
  157.         maxdlevel = dlevel;
  158.     glo(dlevel);
  159.  
  160.     if(!level_exists[dlevel]) mklev();
  161.     else {
  162.         extern int hackpid;
  163.  
  164. #ifdef TOS
  165.         if((fd = open(lock,0x8000)) < 0) { /*no translate*/
  166. #else
  167.         if((fd = open(lock,0)) < 0) {
  168. #endif
  169.             pline("Cannot open %s .", lock);
  170.             pline("Probably someone removed it.");
  171.             done("tricked");
  172.         }
  173.         getlev(fd, hackpid, dlevel);
  174.         (void) close(fd);
  175.     }
  176.  
  177.     if(at_stairs) {
  178.         if(up) {
  179.         u.ux = xdnstair;
  180.         u.uy = ydnstair;
  181.         if(!u.ux) {        /* entering a maze from below? */
  182.             u.ux = xupstair;    /* this will confuse the player! */
  183.             u.uy = yupstair;
  184.         }
  185.         if(Punished && !Levitation){
  186.             pline("With great effort you climb the stairs.");
  187.             placebc(1);
  188.         }
  189.         } else {
  190.         u.ux = xupstair;
  191.         u.uy = yupstair;
  192.         if(inv_weight() + 5 > 0 || Punished){
  193.             pline("You fall down the stairs.");    /* %% */
  194.             losehp(rnd(3), "fall");
  195.             if(Punished) {
  196.                 if(uwep != uball && rn2(3)){
  197.                 pline("... and are hit by the iron ball.");
  198.                 losehp(rnd(20), "iron ball");
  199.                 }
  200.                 placebc(1);
  201.             }
  202.             selftouch("Falling, you");
  203.         }
  204.         }
  205.         { register struct monst *mtmp = m_at(u.ux, u.uy);
  206.           if(mtmp)
  207.         mnexto(mtmp);
  208.         }
  209.     } else {    /* trapdoor or level_tele */
  210.         do {
  211.         u.ux = rnd(COLNO-1);
  212.         u.uy = rn2(ROWNO);
  213.         } while(levl[u.ux][u.uy].typ != ROOM ||
  214.             m_at(u.ux,u.uy));
  215.         if(Punished){
  216.         if(uwep != uball && !up /* %% */ && rn2(5)){
  217.             pline("The iron ball falls on your head.");
  218.             losehp(rnd(25), "iron ball");
  219.         }
  220.         placebc(1);
  221.         }
  222.         selftouch("Falling, you");
  223.     }
  224.     (void) inshop();
  225.     initrack();
  226.  
  227.     losedogs();
  228.     { register struct monst *mtmp;
  229.       if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp);    /* riv05!a3 */
  230.     }
  231.     flags.nscrinh = 0;
  232.     setsee();
  233.     seeobjs();    /* make old cadavers disappear - riv05!a3 */
  234.     docrt();
  235.     pickup(1);
  236.     read_engr_at(u.ux,u.uy);
  237. }
  238.  
  239. donull() {
  240.     return(1);    /* Do nothing, but let other things happen */
  241. }
  242.  
  243. dopray() {
  244.     nomovemsg = "You finished your prayer.";
  245.     nomul(-3);
  246.     return(1);
  247. }
  248.